<template>
    <view>
        <scroll-view v-if="data_list.length > 0" :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="30">
            <view class="content">
                <view class="data-card bg-white br-b" v-for="(item, index) in data_list" :key="index">
                    <view class="data-box oh">
                        <text class="data-title">{{ item.type_text }}</text>
                        <text class="data-time fr">{{ item.add_time_time }}</text>
                    </view>

                    <view class="data-value">
                        <text class="cr-666">原始 {{ item.original_integral }}</text>
                        <text class="cr-main">最新 {{ item.new_integral }}</text>
                    </view>

                    <view class="data-detail">{{ item.msg }}</view>
                </view>
                <view v-if="data_list.length == 0">
                    <component-no-data :prop-status="data_list_loding_status" :prop-msg="data_list_loding_msg"></component-no-data>
                </view>
            </view>

            <component-bottom-line :prop-status="data_bottom_line_status"></component-bottom-line>
        </scroll-view>

        <view v-if="data_list.length == 0">
            <component-no-data :prop-status="data_list_loding_status" :prop-msg="data_list_loding_msg"></component-no-data>
        </view>

        <!-- 结尾 -->
        <component-footer :prop-status="2"></component-footer>
    </view>
</template>

<script>
	import componentPopup from '@/components/popup/popup';
	import componentIconNav from '@/components/icon-nav/icon-nav';
	import componentBanner from '@/components/slider/slider';
	import componentFooter from "@/pages/fcc/scorestore/public/footer";
	import componentNoData from "@/components/no-data/no-data";
	import componentBottomLine from "@/components/bottom-line/bottom-line";
	import componentOnlineService from "@/components/online-service/online-service";
const app = getApp();
export default {
	components: {
	    componentPopup,
		componentIconNav,
		componentBanner,
		componentFooter,
		componentNoData,
		componentBottomLine,
		componentOnlineService
	},
    data() {
        return {
            data_list: [],
            data_page_total: 0,
            data_page: 1,
            data_list_loding_status: 1,
            data_bottom_line_status: false,
            data_total: '',
            data_list_loding_msg: ''
        };
    },
    onShow() {
        app.globalData.page_event_onshow_handle();
        this.init();
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.setData({
            data_page: 1
        });
        this.get_data_list(1);
    },
    methods: {
        init() {
            var user = app.globalData.get_user_info(this, 'init');

            if (user != false) {
                this.get_data_list();
            }
        },

        get_data_list(is_mandatory) {
            // 分页是否还有数据
            if ((is_mandatory || 0) == 0) {
                if (this.data_bottom_line_status == true) {
                    return false;
                }
            } else {
                this.setData({
                    data_bottom_line_status: false
                });
            } // 加载loding

            uni.showLoading({
                title: this.$t('common.loading_in_text'),
            });
            this.setData({
                data_list_loding_status: 1
            }); // 获取数据

            uni.request({
                url: app.globalData.get_request_url('index', 'userintegral'),
                method: 'POST',
                data: {
                    page: this.data_page
                },
                dataType: 'json',
                header: {
                    'content-type': 'application/x-www-form-urlencoded'
                },
                success: (res) => {
                    console.log(res);
                    uni.hideLoading();
                    uni.stopPullDownRefresh();

                    if (res.data.code == 0) {
                        if (res.data.data.data.length > 0) {
                            if (this.data_page <= 1) {
                                var temp_data_list = res.data.data.data;
                            } else {
                                var temp_data_list = this.data_list;
                                var temp_data = res.data.data.data;

                                for (var i in temp_data) {
                                    temp_data_list.push(temp_data[i]);
                                }
                            }

                            this.setData({
                                data_list: temp_data_list,
                                data_total: res.data.data.total,
                                data_page_total: res.data.data.page_total,
                                data_list_loding_status: 3,
                                data_page: this.data_page + 1
                            }); // 是否还有数据

                            if (this.data_page > 1 && this.data_page > this.data_page_total) {
                                this.setData({
                                    data_bottom_line_status: true
                                });
                            }
                        } else {
                            this.setData({
                                data_list_loding_status: 0
                            });
                        }
                    } else {
                        this.setData({
                            data_list_loding_status: 0
                        });
                        app.globalData.showToast(res.data.msg);
                    }
                },
                fail: () => {
                    uni.hideLoading();
                    uni.stopPullDownRefresh();
                    this.setData({
                        data_list_loding_status: 2
                    });
                    app.globalData.showToast(this.$t('common.internet_error_tips'));
                }
            });
        },

        // 导航事件
        navigation_event(e) {
            app.globalData.operation_event(e);
        },

        // 滚动加载
        scroll_lower(e) {
            this.get_data_list();
        }
    }
};
</script>
<style>
@import './scorelist.css';
</style>
